package com.world.web.controller.blog;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.world.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.world.common.annotation.Log;
import com.world.common.core.controller.BaseController;
import com.world.common.core.domain.AjaxResult;
import com.world.common.enums.BusinessType;
import com.world.blog.domain.BlogFriendLink;
import com.world.blog.service.IBlogFriendLinkService;
import com.world.common.utils.poi.ExcelUtil;
import com.world.common.core.page.TableDataInfo;

/**
 * 友链Controller
 * 
 * @author LiJunXi
 * @date 2025-05-25
 */
@RestController
@RequestMapping("/blog/link")
public class FriendLinkController extends BaseController
{
    @Autowired
    private IBlogFriendLinkService friendLinkService;

    /**
     * 查询友链列表
     */
    @PreAuthorize("@ss.hasPermi('blog:link:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlogFriendLink blogFriendLink)
    {
        startPage();
        List<BlogFriendLink> list = friendLinkService.selectFriendLinkList(blogFriendLink);
        return getDataTable(list);
    }

    @Anonymous
    @GetMapping("/front/list")
    public TableDataInfo frontList(BlogFriendLink blogFriendLink)
    {
        startPage();
        List<BlogFriendLink> list = friendLinkService.selectFriendLinkList(blogFriendLink);
        return getDataTable(list);
    }

    /**
     * 导出友链列表
     */
    @PreAuthorize("@ss.hasPermi('blog:link:export')")
    @Log(title = "友链", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlogFriendLink blogFriendLink)
    {
        List<BlogFriendLink> list = friendLinkService.selectFriendLinkList(blogFriendLink);
        ExcelUtil<BlogFriendLink> util = new ExcelUtil<BlogFriendLink>(BlogFriendLink.class);
        util.exportExcel(response, list, "友链数据");
    }

    /**
     * 获取友链详细信息
     */
    @PreAuthorize("@ss.hasPermi('blog:link:query')")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId)
    {
        return success(friendLinkService.selectFriendLinkByLinkId(linkId));
    }

    /**
     * 新增友链
     */
    @PreAuthorize("@ss.hasPermi('blog:link:add')")
    @Log(title = "友链", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogFriendLink blogFriendLink)
    {
        return toAjax(friendLinkService.insertFriendLink(blogFriendLink));
    }

    /**
     * 修改友链
     */
    @PreAuthorize("@ss.hasPermi('blog:link:edit')")
    @Log(title = "友链", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogFriendLink blogFriendLink)
    {
        return toAjax(friendLinkService.updateFriendLink(blogFriendLink));
    }

    /**
     * 删除友链
     */
    @PreAuthorize("@ss.hasPermi('blog:link:remove')")
    @Log(title = "友链", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds)
    {
        return toAjax(friendLinkService.deleteFriendLinkByLinkIds(linkIds));
    }
}
